home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Magazine / UsingPDF / GhostScript / source / gs5.10 / zdps.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-17  |  4.7 KB  |  183 lines

  1. /* Copyright (C) 1997 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* zdps.c */
  20. /* Display PostScript extensions */
  21. #include "ghost.h"
  22. #include "errors.h"
  23. #include "oper.h"
  24. #include "gsstate.h"
  25. #include "gsdps.h"
  26. #include "igstate.h"
  27. #include "iname.h"
  28. #include "store.h"
  29.  
  30. /* Import the user name table. */
  31. extern ref user_names;
  32.  
  33. /* ------ Graphics state ------ */
  34.  
  35. /* <screen_index> <x> <y> .setscreenphase - */
  36. private int
  37. zsetscreenphase(register os_ptr op)
  38. {    int code;
  39.     long x, y;
  40.  
  41.     check_type(op[-2], t_integer);
  42.     check_type(op[-1], t_integer);
  43.     check_type(*op, t_integer);
  44.     x = op[-1].value.intval;
  45.     y = op->value.intval;
  46.     if ( x != (int)x || y != (int)y ||
  47.          op[-2].value.intval < -1 ||
  48.          op[-2].value.intval >= gs_color_select_count
  49.        )
  50.       return_error(e_rangecheck);
  51.     code = gs_setscreenphase(igs, (int)x, (int)y,
  52.                  (gs_color_select_t)op[-2].value.intval);
  53.     if ( code >= 0 )
  54.       pop(3);
  55.     return code;
  56. }
  57.  
  58. /* <screen_index> .currentscreenphase <x> <y> */
  59. private int near
  60. zcurrentscreenphase(register os_ptr op)
  61. {    gs_int_point phase;
  62.     int code;
  63.  
  64.     check_type(*op, t_integer);
  65.     if ( op->value.intval < -1 ||
  66.          op->value.intval >= gs_color_select_count
  67.        )
  68.       return_error(e_rangecheck);
  69.     code = gs_currentscreenphase(igs, &phase,
  70.                      (gs_color_select_t)op->value.intval);
  71.     if ( code < 0 )
  72.       return code;
  73.     push(1);
  74.     make_int(op - 1, phase.x);
  75.     make_int(op, phase.y);
  76.     return 0;
  77. }
  78.  
  79. /* ------ View clipping ------ */
  80.  
  81. /* - viewclip - */
  82. private int
  83. zviewclip(register os_ptr op)
  84. {    return gs_viewclip(igs);
  85. }
  86.  
  87. /* - eoviewclip - */
  88. private int
  89. zeoviewclip(register os_ptr op)
  90. {    return gs_eoviewclip(igs);
  91. }
  92.  
  93. /* - initviewclip - */
  94. private int
  95. zinitviewclip(register os_ptr op)
  96. {    return gs_initviewclip(igs);
  97. }
  98.  
  99. /* - viewclippath - */
  100. private int
  101. zviewclippath(register os_ptr op)
  102. {    return gs_viewclippath(igs);
  103. }
  104.  
  105. /* ------ User names ------ */
  106.  
  107. /* <index> <name> defineusername - */
  108. private int
  109. zdefineusername(register os_ptr op)
  110. {    ref uname;
  111.  
  112.     check_int_ltu(op[-1], max_array_size);
  113.     check_type(*op, t_name);
  114.     if ( array_get(&user_names, op[-1].value.intval, &uname) >= 0 )
  115.       { switch ( r_type(&uname) )
  116.           {
  117.           case t_null:
  118.         break;
  119.           case t_name:
  120.         if ( name_eq(&uname, op) )
  121.           goto ret;
  122.         /* falls through */
  123.           default:
  124.         return_error(e_invalidaccess);
  125.           }
  126.       }
  127.     else
  128.       { /* Expand the array. */
  129.         ref new_array;
  130.         uint old_size = r_size(&user_names);
  131.         uint new_size = (uint)op[-1].value.intval + 1;
  132.  
  133.         if ( new_size < 100 )
  134.           new_size = 100;
  135.         else if ( new_size > max_array_size / 2 )
  136.           new_size = max_array_size;
  137.         else if ( new_size >> 1 < old_size )
  138.           new_size = (old_size > max_array_size / 2 ? max_array_size :
  139.               old_size << 1);
  140.         else
  141.           new_size <<= 1;
  142.         /* The user name array is always allocated in system VM, */
  143.         /* because it must be immune to save/restore. */
  144.         { uint save_space = icurrent_space;
  145.           int code;
  146.  
  147.           ialloc_set_space(idmemory, avm_system);
  148.           code = ialloc_ref_array(&new_array, a_all, new_size,
  149.                       "defineusername(new)");
  150.           if ( code < 0 ) {
  151.         ialloc_set_space(idmemory, save_space);
  152.         return code;
  153.           }
  154.           refcpy_to_new(new_array.value.refs, user_names.value.refs,
  155.                 old_size);
  156.           refset_null(new_array.value.refs + old_size,
  157.               new_size - old_size);
  158.           ifree_ref_array(&user_names, "defineusername(old)");
  159.           ialloc_set_space(idmemory, save_space);
  160.         }
  161.         user_names = new_array;
  162.       }
  163.     ref_assign(user_names.value.refs + op[-1].value.intval, op);
  164. ret:    pop(2);
  165.     return 0;
  166. }
  167.  
  168. /* ------ Initialization procedure ------ */
  169.  
  170. BEGIN_OP_DEFS(zdps_op_defs) {
  171.         /* Graphics state */
  172.     {"1.currentscreenphase", zcurrentscreenphase},
  173.     {"3.setscreenphase", zsetscreenphase},
  174.         /* View clipping */
  175.     {"0eoviewclip", zeoviewclip},
  176.     {"0initviewclip", zinitviewclip},
  177.     {"0viewclip", zviewclip},
  178.     {"0viewclippath", zviewclippath},
  179.         /* User names */
  180.     {"2defineusername", zdefineusername},
  181. END_OP_DEFS(0) }
  182.  
  183.